package com.it.od.od2024;

import java.util.Scanner;

/**
 * @author: liminghui
 * @date: 2024/1/9 22:42
 * @version: 1.0
 * @description: 字符串序列判定/最后一个有效字符[双指针]
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        String L = sc.nextLine();

        int i = 0, j = 0; // 双指针
        while (i < S.length() && j < L.length()) {
            if (S.charAt(i) == L.charAt(j)) {
                i++;
            }
            j++;
        }

        if (i == S.length()) {
            System.out.println(j - 1);
        } else {
            System.out.println(-1);
        }
    }
}
